package com.tedu.demo2;


import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * 使用Spring容器来管理项目中要使用的所有的类
 */
public class Demo {

    public static void main(String[] args) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException, ClassNotFoundException {
        User user = new User();
        user.sayHello();

        Class cls = Class.forName("com.tedu.demo2.User");
        Object obj = cls.newInstance();
        Method method = cls.getMethod("sayHello");
        method.invoke(obj);

        AnnotationConfigApplicationContext context =
                new AnnotationConfigApplicationContext("com.tedu.demo2");
        User user2 = context.getBean(User.class);
        user2.sayHello();
    }
}
